package com.songtao.rabbitmq.tx;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.songtao.rabbitmq.config.RabbitConfig;
import com.songtao.rabbitmq.util.RabbitConnectionUtils;

public class Send {
    
    
    public static void main(String[] args) throws IOException, TimeoutException {
        
        Connection connection = RabbitConnectionUtils.getConnection();
        
        Channel channel = connection.createChannel();
        
        //声明队列
        channel.queueDeclare(RabbitConfig.QUEUE_TX, false, false, false, null);
        
        //消息
        String msg = "hello rabbitmq tx";
        try {
            channel.txSelect();
            channel.basicPublish("", RabbitConfig.QUEUE_TX, null, msg.getBytes());
            channel.txCommit();
        } catch (Exception e) {
            e.printStackTrace();
            channel.txRollback();
            System.out.println("发送失败");
        }
        
        channel.close();
        connection.close();
        
    }
}
